package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_04_治疗;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 谋略（场上每有一个处于X状态的（己方或敌方）单位，为目标恢复施法者X%（生命或攻击）的生命值
 * @date 2022/2/25 12:05
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.谋略)
public class Affix74Strategist extends Buff {
    public Affix74Strategist(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getAppointBuffState() {return getParam(0);}
    private int getCamps() {return getParam(1);}
    private PropertyType getPropertyType() {return PropertyType.forNumber(getParam(2));}
    private int getAddPer() {return getParam(3);}

    private RecordStreamGroup steamGroup;

    @Override
    public RecordStreamGroup record() {
        steamGroup = getRecord().stream(new RecordStreamGroup());
        steamGroup.add(new RecordStream_SKL(getActor(), this.getSkilldata().getId()));
        return steamGroup;
    }

    @Override
    public boolean exec(Fighter source, Fighter target) {
        int number = 0;
        if(getCamps() == CAMPS_SELF){
            number = source.getTeam().getLiveAppendSpecialBuff(getAppointBuffState()).size();
        }else if(getCamps() == CAMPS_OPPONENT){
            number = source.getTeam().getTeam对手().getLiveAppendSpecialBuff(getAppointBuffState()).size();
        }else if(getCamps() == CAMPS_BOTH){
            number = source.getTeam().getLiveAppendSpecialBuff(getAppointBuffState()).size() +
                    source.getTeam().getTeam对手().getLiveAppendSpecialBuff(getAppointBuffState()).size();
        }

        PropertyType type = getPropertyType();
        long addValue = 0;
        if(type != null && getAddPer() > 0){
            addValue = source.getData().getPropertyData().getValue(type);
            addValue = addValue * getAddPer() * number/VALUE_比率分母;
            target.set治疗(addValue);

            RecordStream_04_治疗 recordSteam = steamGroup.add(new RecordStream_04_治疗(target,addValue));
            recordSteam.record();
        }

        Battle.battleLogger(6,"谋略："+source.getName()+"处于异常状态："+getAppointBuffState()+"玩家数量："+number+"治疗："+addValue);

        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.strategistState;
    }

}
